package com.zhouyu.mybatis.mybatis;

import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author by gang.Li 2022/4/7 15:54
 */
@Component
public class MyBatisImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {

	@Override
	public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
		Map<String, Object> annotationAttributes = importingClassMetadata.getAnnotationAttributes(MybatisMapperScan.class.getName());
		assert annotationAttributes != null;
		String path = (String) annotationAttributes.get("value");

		// 构建scanner
		MyBatisMapperScanner scanner = new MyBatisMapperScanner(registry);
		scanner.scan(path);
	}
}
